package co.edu.udea.iw.dao.impl;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import co.edu.udea.iw.dao.GerenteDAO;
import co.edu.udea.iw.dto.gerente;

import co.edu.udea.iw.exception.waDaoException;

public class GerenteDAOHibernate extends HibernateDaoSupport implements GerenteDAO {

	@Override
	public gerente obtenerGerente(String cedula) throws  waDaoException{
		gerente Gerente = null;
		try{
		 Session 	session= getSession();
		 
		 Criteria criteria  = session.createCriteria(gerente.class).add(Restrictions.eq("cedula", cedula));
		 Gerente= (gerente)criteria.uniqueResult();
		}catch(HibernateException e){
			
			throw new waDaoException(e);
		}
		return Gerente;
	}
	
	public gerente insertar(gerente Gerente) throws waDaoException{
	
	Transaction tx = null;
	Session session = null;
	try {
		session = getSession();
		tx = session.beginTransaction();
		session.save(Gerente);
		tx.commit();

	} catch (HibernateException e) {

		throw new waDaoException(e);
	} finally {
	   session.close();
	}
	return Gerente;
	
	}

}
